﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KantoorDienst
{
    public partial class CaliberEdit : Form
    {
        DBConnect db; 
        public CaliberEdit()
        {
            InitializeComponent();
        }

        private void WeaponEdit_Load(object sender, EventArgs e)
        {
            db = new DBConnect();
            getCalibers();
            FillFields();
        }
        private void getCalibers()
        {
            caliberBox.DisplayMember = "name";
            caliberBox.ValueMember = "cal_id";
            caliberBox.DataSource = db.getCaliberList();
        }
        private void FillFields()
        {
            caliberNameTxt.Text = ((DataRowView)caliberBox.SelectedItem)["name"].ToString();
            sizeTxt.Text = ((DataRowView)caliberBox.SelectedItem)["size"].ToString();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            db.setCaliberNameSize(caliberBox.SelectedValue.ToString(), caliberNameTxt.Text, sizeTxt.Text);
            getCalibers();
        }

        private void newBtn_Click(object sender, EventArgs e)
        {
            db.newCaliber();
            getCalibers();
        }

        private void caliberBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillFields();
        }
    }
}
